<%@ page import="java.util.ArrayList"%>
<%@ page import="domain.Contact"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic"%>
<%@ taglib prefix="nested" uri="http://struts.apache.org/tags-nested"%>
<!DOCTYPE html>
<html:html>
<head>
<title><bean:message key="searchContacts.title" /></title>
<jsp:include page="/pages/header.jsp" />
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="span12">
				<div class="page-header">
					<h1>
						<bean:message key="searchContacts.title" />
					</h1>
				</div>
			</div>
		</div>
		<div class="row">
			<jsp:include page="/pages/navbar.jsp" />
			<div class="span10">
				<%ArrayList<Contact> contacts = (ArrayList<Contact>) request.getAttribute("contacts");%>
					<% if(contacts != null){
					%><table class="table table-hover">
						<tr class="bandeau"><th>Id</th><th>Prénom</th><th>Nom</th><th>Email</th><th></th><th></th><th></th></tr>
			<%
					for(int i=0; i < contacts.size();i++){
						String formId = "form-".concat(String.valueOf(contacts.get(i).getId()));
						%> 
					<tr>
						<td><%= contacts.get(i).getId()%></td> 
						<td><%= contacts.get(i).getFirstName()%></td>
						<td><%= contacts.get(i).getLastName()%></td>
						<td><%= contacts.get(i).getEmail()%></td>
						<td>
							<html:form styleClass="showForm" action="/showContact">
							<html:hidden property="id" value="<%=String.valueOf(contacts.get(i).getId())%>"/>
							<button type="submit" name="btnShowSimple" class="btnShowSimple btn btn-small btn-primary"><i class="icon-white icon-user"></i>&nbsp;<bean:message key="showContactButton" /></button>
							</html:form>
						<td>
							<html:form styleClass="updateForm" action="/updateContactLink">
							<html:hidden property="id" value="<%=String.valueOf(contacts.get(i).getId())%>"/>
							<button type="submit" name="btnUpdateSimple" class="btn btn-small btn-primary"><i class="icon-white icon-pencil"></i>&nbsp;<bean:message key="updateContactButton" /></button>
							</html:form>
						<td>
							<html:form styleClass="deleteForm" styleId="<%=formId%>" action="/deleteContact">
							<html:hidden property="id" value="<%=String.valueOf(contacts.get(i).getId())%>"/>
							<button type="submit" name="btnDeleteSimple" id="<%=String.valueOf(contacts.get(i).getId())%>" class="btnDeleteSimple btn btn-small btn-primary"><i class="icon-white icon-remove-sign"></i>&nbsp;<bean:message key="deleteContactButton" /></button>
							</html:form>
					</tr>	
						<%}%>
				<%}%>
		</table>
		<html:form action="/searchContact" styleClass="form-search" styleId="formulaire">
					<span class="help-inline"><bean:message key="searchBy" /></span>&nbsp;
					<html:select property="searchBy" styleId="simple" styleClass="input-medium">
						<html:option value="lastname">
							<bean:message key="lastNameLabel" />
						</html:option>
						<html:option value="firstname">
							<bean:message key="firstNameLabel" />
						</html:option>
						<html:option value="email">
							<bean:message key="emailLabel" />
						</html:option>
					</html:select>
						<html:text property="searchValue" styleClass="search-query" styleId="search-field"/>
						<button type="submit" name="submitButton" class="btn btn-primary"><i class="icon-white icon-search"></i>&nbsp;<bean:message key="searchButton" /></button>
				</html:form>
				
			</div>
		</div>
		<jsp:include page="/pages/footer.jsp" />
	</div>
</body>
</html:html>